<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page import="util.PageBean" %>
<%@ page import="service.GoodsService" %>
<%@ page import="service.impl.GoodsServiceImpl" %>
<%@ page import="pojo.Goods" %>
<%@ page import="java.util.List" %><%--
  Created by IntelliJ IDEA.
  User: 周超
  Date: 2019/1/21
  Time: 14:36
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>分页查询</title>

</head>
<body>

<tr>
    <td><input id="name" name="name" type="text" value="${goName}" placeholder="请输入商品名称"></td>
    <td><input type="button" value="查询" onclick="chaxun()"></td>
    <td><input type="button" value="新增" onclick="addGoods()"/></td>
    <td><input type="button" value="全选" onclick="chooseAll()"/></td>
    <td><input type="button" value="取消选择" onclick="unChoose()"/></td>
    <td><input type="button" value="批量删除" onclick="deleteAll()"/></td>
    <td><input type="file" id="file" value=""/></td>
    <td><input type="button" value="确定导入" onclick="pullIn()"/></td>
    <td><input type="button" value="批量导出" onclick="pullOut()"/></td>
    <td><input type="button" value="商品分类" onclick="GoodsClass()"/></td>
</tr>
<table style="align-content: center">
    <tr>
        <td>选择</td>
        <td>商品id</td>
        <td>商品名称</td>
        <td>商品销量</td>
        <td>商品评价</td>
        <td>上架时间</td>
        <td>图片地址</td>
        <td>商品描述</td>
        <td>商品成本</td>
        <td>商品价格</td>
        <td>商品库存</td>
        <td>商品状态</td>
        <td>商品所属分类id</td>
        <td>商品所属分类名称</td>
        <td>商品是否参与秒杀</td>
        <td colspan="2">操作</td>
    </tr>


    <c:forEach var="go" items="${pb.list}">
        <tr>
            <td><input type="checkbox" name="box" value="${go.goId}"></td>
            <td>${go.goId}</td>
            <td>${go.goName}</td>
            <td>${go.goSalesVolume}</td>
            <td>${go.goPraise}颗星</td>
            <td>${go.goUptime}</td>
            <td><a href="images/${go.goPictureUrl}">${go.goPictureUrl}</a></td>
            <td>${go.goDescribe}</td>
            <td>${go.goCost}</td>
            <td>${go.goPrice}</td>
            <td>${go.goStock}</td>
            <td>${go.state}</td>
            <td>${go.clId}</td>
            <td>${go.clName}</td>
            <td>${go.secKill}</td>
            <td><input type="button" value="修改" onclick="modify(${go.goId})"/></td>
            <td><input type="button" value="删除" onclick="deleteMessage(${go.goId})"/></td>
        </tr>
    </c:forEach>

</table>

    <input id="shouye" type="button" value="首页" onclick="shouye()">
    <input id="shangye" type="button" value="上一页" onclick="shangye()">
    <input id="text" type="text" value="${pb.pageIndex}|${pb.totalPage}" onclick="tiaozhuan()">
    <input id="xiaye" type="button" value="下一页" onclick="xiaye()">
    <input id="weiye" type="button" value="尾页" onclick="weiye()">

</body>
<script type="text/javascript">
    
    function chooseAll() {
        var str=document.getElementsByName("box");
        for(var i=0;i<str.length;i++){
            str[i].checked=true;
        }
    }

    function unChoose() {
        var str=document.getElementsByName("box");
        for(var i=0;i<str.length;i++){
            str[i].checked=false;
        }
    }

    function deleteAll() {
        var str=document.getElementsByName("box");
        var s="";
        for(var i=0;i<str.length;i++){
            if(str[i].checked==true){
                s=s.concat(str[i].value);
                s=s.concat("_");
            }
        }
        if(s==""){
            alert("未选择任何数据");
            return false;
        }
        window.location.href="DeleteAllGoodsServlet?s="+s;
    }

    function pullIn() {
        var file=document.getElementById("file").value;
        if(file==""||file==null){
            alert("未选择任何文件");
            return false;
        }
        file="D:\\files\\customer.xls";
        window.location.href="PullInServlet";
    }


    function pullOut() {
        var str=document.getElementsByName("box");
        var s="";
        for(var i=0;i<str.length;i++){
            if(str[i].checked==true){
                s=s.concat(str[i].value);
                s=s.concat("_");
            }
        }
        if(s==""){
            alert("未选择任何数据");
            return false;
        }
        window.location.href="PullOutServlet?s="+s;
    }

    function GoodsClass() {
        window.location.href="GoodsClassPageBeanListServlet";
    }


    function chaxun() {
        var goname=document.getElementById("name").value;
        window.location.href="GoodsPageBeanListServlet?pageIndex=1&goName="+goname;
    }
    function modify(goId) {
        var bo=confirm("您确定要修改这条商品信息吗");
        if(bo){
            //window.location.href="GoodsDetailsServlet?goId="+goId;
            window.location.href="GoodsModifyServlet?goId="+goId;

        }
        else{
            alert("已经取消修改");
        }
    }
    function deleteMessage(goId) {
        var bo=confirm("您确定要删除这条商品信息吗");
        if(bo){
            window.location.href="DeleteGoodsServlet?goId="+goId;
            alert("已删除该商品");
        }
        else{
            alert("已经取消删除");
        }
    }
    function addGoods() {
        window.location.href="AddGoodsServlet";
        //response.sendRedirect("ListEmp2.jsp");
    }

    function shouye() {
        var goname=document.getElementById("name").value;
        window.location.href="GoodsPageBeanListServlet?pageIndex=1&goName="+goname;
    }
    function shangye() {
        var goname=document.getElementById("name").value;
        //应该获取当前页码
        var pageIndex="${pb.pageIndex}";
        if(1==pageIndex){
            alert("已经是第一页了");
        }else{
            pageIndex--;
            window.location.href="GoodsPageBeanListServlet?pageIndex="+pageIndex+"&goName="+goname;
        }
    }
    
    function tiaozhuan() {
        
    }
    
    function xiaye() {
        var goname=document.getElementById("name").value;
        //应该获取当前页码
        var pageIndex="${pb.pageIndex}";
        var pageTotal="${pb.totalPage}";

        if(pageIndex<pageTotal){
            pageIndex++;
            window.location.href="GoodsPageBeanListServlet?pageIndex="+pageIndex+"&goName="+goname;
        }else{
            alert("已经是最后一页了");
        }

    }

    function weiye() {
        var goname=document.getElementById("name").value;
        var pageTotal="${pb.totalPage}";
        window.location.href="GoodsPageBeanListServlet?pageIndex="+pageTotal+"&goName="+goname;
    }
</script>
</html>
